package com.tjbklx1.dubbo.validate;

import java.util.Date;
import java.util.Set;

import javax.validation.ConstraintViolation;
import javax.validation.ConstraintViolationException;

import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.alibaba.dubbo.rpc.RpcException;

public class ValidationTest {

	public static void main(String[] args) {
		System.out.println("aaaaaaaaaaaa");

		ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[] { "consumer.xml" });
		context.start();

		System.out.println("app run ");

		ValidationService validationService = (ValidationService) context.getBean("validationService");
		ValidationParameter parameter = new ValidationParameter();
			parameter.setName("abc");
//			parameter.setLoginDate(new Date());
//			parameter.setExpiryDate(new Date());
		parameter.setAge(20);
		parameter.setEmail("han@qq.com");
		try {
			String result = validationService.validate(parameter);
			System.out.println(result);
		} catch (RpcException e) { // 抛出的是RpcException
			ConstraintViolationException ve = (ConstraintViolationException) e.getCause(); // 里面嵌了一个ConstraintViolationException
			Set<ConstraintViolation<?>> violations = ve.getConstraintViolations(); // 可以拿到一个验证错误详细信息的集合
			System.out.println(violations);
//				e.printStackTrace();
		}
	}
}
